package com.sharp.core.voxel;

import java.util.ArrayList;
import java.util.List;

import com.sharp.core.graphics.Light;
import com.sharp.core.math.Vec3;
import com.sharp.core.raytrace.Intersection;
import com.sharp.core.raytrace.Ray;
import com.sharp.core.utils.LineClip;

public class ListVoxelScene extends VoxelHolder {

	private List<VoxelObject> list = new ArrayList<VoxelObject>();
	
	@Override
	public void addObject(VoxelObject data) {
		list.add(data);
	}

	@Override
	public void addLight(Light p) {
		
	}

	@Override
	public Intersection findIntersection(Ray ray) {
		Voxel voxel = null;
		float min = Float.MAX_VALUE;
		for ( VoxelObject obj : list ) {
			float t = LineClip.RayAABB(obj.getAABB(), ray);
			if ( t > 0 && t < min ) {
				ray.setT(t);
				Voxel v = obj.findIntersection(ray);
				if ( v != null )
					voxel = v;
				min = t;
			}
		}
		if ( voxel == null )
			return null;
		VoxelIntersection inter = new VoxelIntersection(this);
		inter.setVoxel(voxel);
		inter.setSide(Voxel.Side.FRONT);
		//inter.setPos(new Vec3( mapX, mapY, mapZ ));
		return inter;
	}

	@Override
	public boolean isVisible(Intersection from, Light l) {
		return false;
	}

	@Override
	public boolean isIntersected(Ray ray) {
		return false;
	}

	@Override
	public Iterable<Light> getLights() {
		return null;
	}

}
